package world;  

import java.nio.FloatBuffer;

import math.Vector3f;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;

public class Coordinator {
	private static final float UNIT_LEN=5F;
	private static final float UNIT_LEN_ANTI=-5F;
	private static final Vector3f ORIGIN = new Vector3f(0f, 0f, 0f);
	private static final Vector3f UNIT_X = new Vector3f(UNIT_LEN, 0f, 0f);
	private static final Vector3f UNIT_Y = new Vector3f(0f, UNIT_LEN, 0f);
	private static final Vector3f UNIT_Z = new Vector3f(0f, 0f, UNIT_LEN);
	private static final Vector3f UNIT_X_ANTI  = new Vector3f(UNIT_LEN_ANTI, 0f, 0f);
	private static final Vector3f UNIT_Y_ANTI  = new Vector3f(0f, UNIT_LEN_ANTI, 0f);
	private static final Vector3f UNIT_Z_ANTI  = new Vector3f(0f, 0f, UNIT_LEN_ANTI);
	private static final Vector3f[] UNIT_ARRAY ={UNIT_X,UNIT_Y,UNIT_Z,UNIT_X_ANTI,UNIT_Y_ANTI,UNIT_Z_ANTI};

	public static final int UNIT_ARRAY_SIZE =UNIT_ARRAY.length;
	
	private static final float[] COLOR = new float[] { 1, 1, 0 };

	public static final int AXIS_POINT_COUNT= 200;
	private Vector3f[][] vertexes = new Vector3f[UNIT_ARRAY_SIZE][AXIS_POINT_COUNT];

	
	public FloatBuffer[] verticesBuffers = new FloatBuffer[UNIT_ARRAY_SIZE];

	public static final int positionElementCount=3;
	public static final int colorElementCount=3;
	public static final int positionByteOffset=0;
	public static final int colorByteOffset=3;
	public static final int stride=colorElementCount+positionElementCount;
	
	public Coordinator() {
		createVertexes();
		buildRenderData();
	}

	public void createVertexes() {
		for (int i = 0; i < UNIT_ARRAY_SIZE; i++) {
			Vector3f unit = UNIT_ARRAY[i];
			for (int j = 0; j < AXIS_POINT_COUNT; j++) {
				Vector3f point = (unit.copy()).normalize();
				vertexes[i][j] = Vector3f.add(ORIGIN,point.mult(j*UNIT_LEN));
			}
		}
	}

	public void buildRenderData() {
		for (int i = 0; i < UNIT_ARRAY_SIZE; i++) {
			verticesBuffers[i] = BufferUtils.createFloatBuffer(4*(positionElementCount+colorElementCount)*AXIS_POINT_COUNT );
			for (int j = 0; j < AXIS_POINT_COUNT; j++) {
				verticesBuffers[i].put(vertexes[i][j].toArray());
			}
			
			for (int j = 0; j < AXIS_POINT_COUNT; j++) {
				verticesBuffers[i].put(COLOR);
			}
			verticesBuffers[i].flip();
		}
		
	}
}